package com.rock.platform.service;

import java.io.Serializable;
import java.util.List;
import org.springframework.transaction.annotation.Transactional;

import com.rock.platform.dao.IGenericDao;

@Transactional(rollbackFor = { Exception.class })
public class GenericService implements IGenericService {
	private IGenericDao baseDao;

	public <T, ID extends Serializable> T findByID(ID id, boolean lock,
			Class<T> entityType) {
		return this.baseDao.findByID(id, lock, entityType);
	}

	public <T> List<T> findAll(Class<T> entityType) {
		return this.baseDao.findAll(entityType);
	}

	public <T> void add(T entity) {
		this.baseDao.add(entity);
	}

	public <T> T update(T entity) {
		return this.baseDao.merge(entity);
	}

	public <T> void delete(T entity) {
		this.baseDao.delete(entity);
	}

	public <T, ID extends Serializable> void deleteByID(ID id,
			Class<T> entityType) {
		this.baseDao.deleteByID(id, entityType);
	}

	public void flush() {
		this.baseDao.flush();
	}

	public void clear() {
		this.baseDao.clear();
	}

	public IGenericDao getBaseDao() {
		return this.baseDao;
	}

	public void setBaseDao(IGenericDao baseDao) {
		this.baseDao = baseDao;
	}
}
